﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product.Base;
using ERP_RORZE_PERMISSION.Base;

namespace ERP_RORZE_PRODUCT.Product.MonthlyCharge
{
    public partial class ctrlMonthlyExpence : DevExpress.XtraEditors.XtraUserControl
    {
        ClsMonthlyExpenceDAO clsMonthlyExpenceDAO = new ClsMonthlyExpenceDAO();
        private LogUtils log;
        DataTable dt;
        MonthlyExpence b = new MonthlyExpence();

        public ctrlMonthlyExpence()
        {
            InitializeComponent();
            log = new LogUtils();
        }

        void Reload(object sender, EventArgs e)
        {
            dt = clsMonthlyExpenceDAO.GetAllMonthlyExpence();
            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();
        }
        private void ctrlMonthlyExpence_Load(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            frm_MonthlyExpenceAdd frmAdd = new frm_MonthlyExpenceAdd();
            frmAdd.Reload += new EventHandler(Reload);
            frmAdd.Show();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                frm_MonthlyExpenceEdit frmEdit = new frm_MonthlyExpenceEdit();
                frmEdit.Reload += new EventHandler(Reload);
                frmEdit.ExpenceID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ExpenceID").ToString();
                frmEdit.YearMonth = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "YearMonth").ToString();
                frmEdit.Amount = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Amount").ToString();
                frmEdit.Show();
            }
            catch
            {
            }
        }

        private void bntDelete_Click(object sender, EventArgs e)
        {
            b.ID = int.Parse(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString());
            clsMonthlyExpenceDAO.DeleteMonthlyExpence(b);

            //write Log
            log.Table = LogConstant.Table.Product.Monthly_Expence;
            log.Task = LogConstant.Task.Delete;
            log.Description = "ExpenceID: " + gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ExpenceID") + "; YearMonth: " + gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "YearMonth") + "; Amount: " + gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Amount");
            log.WriteLog();

            Reload(sender, e);
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            btnAddNew_Click(sender, e);
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            btnEdit_Click(sender, e);
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            bntDelete_Click(sender, e);
        }

        private void btnMonthlyChargeUpdate_Click(object sender, EventArgs e)
        {
            frm_MonthlyChargeUpdate frmObj = new frm_MonthlyChargeUpdate();
            frmObj.Text = "Monthly Charge Update";
            frmObj.Show();
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            clsConstantsFuction.ExportToExcel(gridView1, 1, true);
        }
    }
}
